import { createApp } from 'vue';

import { registerAccessDirective } from '@vben/access';
import { initStores } from '@vben/stores';
import '@vben/styles';
import '@vben/styles/antd';

// import '@surely-vue/table/src/style/antdv.less';
// import { Icon } from '@iconify/vue';

import STable from '@surely-vue/table';

import { setupI18n } from '#/locales';

import { initComponentAdapter } from './adapter/component';
import App from './app.vue';
import components from './components';
import { router } from './router';
import { registerBindShopDirective } from './utils/directive';

async function bootstrap(namespace: string) {
  // 初始化组件适配器
  await initComponentAdapter();

  const app = createApp(App);

  // 国际化 i18n 配置
  await setupI18n(app);

  // 配置 pinia-tore
  await initStores(app, { namespace });

  // 安装权限指令
  registerAccessDirective(app);

  // 安装绑定店铺指令
  registerBindShopDirective(app);

  // 注册全局组件
  // app.component('Icon', Icon);
  app.use(components);
  app.use(STable);
  // 配置路由及路由守卫
  await app.use(router);

  app.mount('#app');
}

export { bootstrap };
